package com.example.nick.bodyapplication.recycler;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.nick.bodyapplication.R;

import java.util.List;

class PlayAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {

    public PlayAdapter(int layoutResId, @Nullable List<Integer> data) {
        super(layoutResId, data);
        addChildClickViewIds(R.id.itemIvPlay);
    }

//    @NonNull
//    @Override
//    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
//        view.getLayoutParams().height = parent.getHeight() / 3;
//        return new BaseViewHolder(view);
////      return super.onCreateViewHolder(parent, viewType);
//    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Integer integer) {
        baseViewHolder.setText(R.id.tvShow, "item:"+integer);
        baseViewHolder.setBackgroundColor(R.id.itemRoot, getItemBgColor(getItemPosition(integer)));
        RelativeLayout itemRoot = baseViewHolder.findView(R.id.itemRoot);
        Log.i("list", "itemRoot w:"+itemRoot.getWidth()+", h:"+itemRoot.getHeight());
    }
    
    private int getItemBgColor(int item)  {
        switch (item % 4) {
            case 1:
                return getContext().getColor(R.color.purple_200);
            case 2:
                return getContext().getColor(R.color.purple_500);
            case 3:
                return getContext().getColor(R.color.teal_200);
            default:
                return getContext().getColor(R.color.purple_700);
        }
    }
}
